package cn.swust.designpatternlearningplatform.dao;

import cn.swust.designpatternlearningplatform.domain.bo.DailyExerciseBo;
import cn.swust.designpatternlearningplatform.domain.dto.DailyExerciseDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DailyExerciseDao {
    /**
     * 查询做题记录（同一道题查询最近的一次记录）
     *
     * @param dailyExerciseBo
     * @return cn.swust.designpatternlearningplatform.domain.dto.DailyExerciseDto
     * @author Tang
     * @date 2023/4/21 16:31
     **/
    @Select("SELECT topic_id,own_answer,MAX(problem_time) as problem_time " +
            "FROM daily_exercise " +
            "WHERE student_number = '${daily.studentNumber}' " +
            "AND topic_id = '${daily.topicId}' " +
            "AND is_right = '${daily.isRight}'" +
            "GROUP BY topic_id")
    DailyExerciseDto selectByStudentNumber(@Param("daily") DailyExerciseBo dailyExerciseBo);

    /**
     * 查询指定题目id下的所有做题记录
     *
     * @param dailyExerciseBo
     * @return cn.swust.designpatternlearningplatform.domain.dto.DailyExerciseDto
     * @author Tang
     * @date 2023/5/13 21:13
     **/
    @Select("SELECT topic_id,own_answer,is_right " +
            "FROM daily_exercise " +
            "WHERE topic_id = ${daily.topicId}")
    List<DailyExerciseDto> selectByTopicId(@Param("daily") DailyExerciseBo dailyExerciseBo);

    /**
     * 查询学生做过题目的id
     *
     * @param studentNumber
     * @return java.util.List<java.lang.Integer>
     * @author Tang
     * @date 2023/11/9 16:25
     **/
    List<Integer> recordOfStudent(@Param("student") String studentNumber, @Param("pointId") Integer pointId,
                                  @Param("start") Integer start, @Param("num") Integer num);

    /**
     * 查询学生做的题的总数量
     *
     * @param studentNumber
     * @return java.lang.Integer
     * @author Tang
     * @date 2023/11/9 16:47
     **/
    Integer totalOfStudent(@Param("student") String studentNumber);
}
